package org.tau.workshop2011.parsing.AST

import org.tau.workshop2011.dynamic.RuntimeEnvironment
import org.tau.workshop2011.expressions._
import org.tau.workshop2011.semantics.ConflictingTypesException

/**
 * A general expression - something that can be computed to produce a value
 */
trait Expr extends ASTNode {
  var resultType = Type.tUnknown

  /**
   * Try to automatically infer the type of this expression and/or it's
   * sub-expressions.
   */
  def autoResolveType { }

  def resolveTypeTo (newType:Type) : Unit = {
    resultType match {
      case Type.tUnknown => resultType = newType
      /* Back-ticks are used to tell Scala not to define a new variable, but to
       * use the existing newType variable (from the outer scope) as a value in
       * the pattern matching */
      case `newType` =>
      case _ => throw new ConflictingTypesException(this, newType)
    }
  }

}
